﻿var Bicycle = new Interface("Bicycle", ['assemble', 'wash', 'ride', 'repair']);
var BicycleShop = function () { };
BicycleShop.prototype = {
    sellBicycle: function (model) {
        var bicycle = this.createBicycle(model);

        bicycle.assemble();
        bicycle.wash();

        return bicycle;
    },
    createBicycle: function (model) {
        throw new Error("Unsupported operation on an abstract class.");
    }
};

var SilverBicycleShop = function () { };
extend(SilverBicycleShop, BicycleShop);
SilverBicycleShop.prototype.createBicycle = function (model) {
    var bicycle;

    switch (model) {
        case "The Speedster":
            bicycle = new Speedster();
            break;
        case "The Lowrider":
            bicycle = new Lowrider();
            break;
        case "The Comfort Cruiser":
        default:
            bicycle = new ComfortCruiser();
    }

    Interface.ensureImplements(bicycle, Bicycle);
    return bicycle;
}

//var BicycleFactory = {
//    createBicycle: function (model) {
//        var bicycle;

//        switch (model) {
//            case "The Speedster":
//                bicycle = new Speedster();
//                break;
//            case "The Lowrider":
//                bicycle = new Lowrider();
//                break;
//            case "The Comfort Cruiser":
//            default:
//                bicycle = new ComfortCruiser();
//        }

//        Interface.ensureImplements(bicycle, Bicycle);
//        return bicycle;
//    }
//}



var Speedster = function () {
    this.No = this.getGuid();
};

Speedster.prototype = {
    getGuid: function () {
        var guid = "";
        for (var i = 1; i <= 32; i++) {
            var n = Math.floor(Math.random() * 16.0).toString(16);
            guid += n;
            if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
                guid += "-";
        }
        return "Speedster" + guid;
    },
    assemble: function () {
        console.log(this.No + " is assembling");
    },
    wash: function () {
        console.log(this.No + " is washing");
    },
    ride: function () {
        console.log(this.No + " is riding");
    },
    repair: function () {
        console.log(this.No + " is repairing");
    },

}